<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link rel="stylesheet" th:href="@{/layui/css/layui.css}"  media="all">
<style>
	.layui-upload-img {
		max-width: 100%;
	}
	.layui-input-block {
		margin-left: auto;
	}
</style>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="layui-form form-horizontal m" id="form-tChapter-edit" th:object="${tChapter}">
            <input id="chapterId" name="chapterId" th:field="*{chapterId}"  type="hidden">
			<div class="form-group">	
				<label class="col-sm-3 control-label">课程主键ID：</label>
				<div class="col-sm-8">
					<input id="courseId" name="courseId" th:field="*{courseId}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">小节名称：</label>
				<div class="col-sm-8">
					<input id="chapterName" name="chapterName" th:field="*{chapterName}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group" id="pdf">
				<label class="col-sm-3 control-label">pdf：</label>
				<div class="col-sm-8">
					<button type="button" class="layui-btn" id="pdfupload"><i class="layui-icon"></i>上传文件</button>
					<input id="pdfUrl" name="pdfUrl" type="hidden" class="form-control" th:field="*{pdfUrl}">
				</div>
			</div>
			<div class="form-group" id="video">
				<label class="col-sm-3 control-label">视频：</label>
				<div class="col-sm-8">
					<button type="button" class="layui-btn" id="videoupload"><i class="layui-icon"></i>上传文件</button>
					<input id="videoUrl" name="videoUrl" type="hidden" th:field="*{videoUrl}" class="form-control">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">小节描述：</label>
				<div class="col-sm-8">
					<input id="remark" name="remark" th:field="*{remark}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">小节状态：</label>
				<div class="col-sm-8">
					<div class="layui-form-item">
						<div class="layui-input-block">
							<input type="radio" name="status" value="0" title="开启" th:field="*{status}">
							<input type="radio" name="status" value="1" title="禁用" th:field="*{status}">
						</div>
					</div>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">文件名称：</label>
				<div class="col-sm-8">
					<input id="fileName" name="fileName" th:field="*{fileName}" class="form-control" disabled="true" type="text">
				</div>
			</div>
		</form>
    </div>
    <div th:include="include::footer"></div>
	<script th:src="@{/layui/layui.all.js}" charset="utf-8"></script>
    <script type="text/javascript">
		//判断该小节文件是pdf还是video
		$(function() {
			var pdf = $("#pdfUrl").val();
			if("" != pdf && null != pdf) {
				$("#video").css("display","none");
			} else {
                $("#pdf").css("display","none");
			}
		});
        layui.use('upload', function(){
            var $ = layui.jquery
                ,upload = layui.upload;

            //普通图片上传
            var uploadInst = upload.render({
                elem: '#cover'
                ,url: '/common/upload'
                ,before: function(obj){
                    //预读本地文件示例，不支持ie8
                    obj.preview(function(index, file, result){
                        $('#coverurl').attr('src', result); //图片链接（base64）
                    });
                },
                done: function(res){
                    //如果上传失败
                    if(res.code > 0){
                        return layer.msg('上传失败');
                    }else {
                        $("#pic_url").attr("value",res.url);
                    }
                    //上传成功
                }
            });
            //绑定原始文件域 上传PDF
            upload.render({
                elem: '#pdfupload'
                ,url: '/common/upload'
                ,exts: 'pdf' //只允许上传PDF
                ,done: function(res){
                    console.log(res);
                    $("#pdfname").text(res.oldFileName);
                    $("#pdfUrl").attr("value", res.url);
                }
            });
            //绑定原始文件域 上传视频
            upload.render({
                elem: '#videoupload'
                ,url: '/common/upload'
                ,exts: 'MP4|mp4|avi|wmv' //只允许上传PDF
                ,done: function(res){
                    console.log(res);
                    $("#videoname").text(res.oldFileName);
                    $("#videoUrl").attr("value", res.url);
                }
            });
        });
        layui.use('form', function(){
            var form = layui.form;
            form.render();
        });

		var prefix = ctx + "system/tChapter";
		$("#form-tChapter-edit").validate({
			rules:{
                courseName:{
                    required:true,
                },
                chapterName:{
                    required:true,
                },
                remark:{
                    required:true,
                },
			}
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/edit", $('#form-tChapter-edit').serialize());
	        }
	    }
	</script>
</body>
</html>
